package bt.sim.grade;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
/**
 * Grade model.

将表结构放在此，消除记忆负担
mysql> desc t_grade;
+-----------+---------------+------+-----+---------+----------------+
| Field     | Type          | Null | Key | Default | Extra          |
+-----------+---------------+------+-----+---------+----------------+
| id        | int(11)       | NO   | PRI | NULL    | auto_increment |
| gradeName | varchar(20)   | YES  |     | NULL    |                |
| gradeDesc | varchar(1000) | YES  |     | NULL    |                |
+-----------+---------------+------+-----+---------+----------------+

数据库字段名建议使用驼峰命名规则，便于与 java 代码保持一致，如字段名： userId
 */
public class Grade extends Model<Grade> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 所有 sql 与业务逻辑写在 Model 或 Service 中，不要写在 Controller 中，养成好习惯，有利于大型项目的开发与维护
	 */
	public static final Grade me = new Grade();
	
	public Page<Grade> paginate(int pageNumber, int pageSize, String gradeName) {
		StringBuilder sb = new StringBuilder("from t_grade");
		if(StrKit.notBlank(gradeName)) {
			sb.append(" and gradeName like '%"+gradeName+"%'");
		}
		return paginate(pageNumber, pageSize, "select *", sb.toString().replaceFirst("and", "where"));
	}
	public int gradeRemove(String delIds) {
		String sql = "delete from t_grade where id in ("+delIds+")";
		return Db.update(sql);
	}
	public Map<String, Object> getAttrs(){
	    return super.getAttrs();
	}
}
